function SaveToDatabaseFunction(e) {
	$(function() {
		$("#dialog-add_confirm").dialog({
			resizable : true,
			height : 500,
			modal : true,
			buttons : {
				"確定" : function() {
					$(this).dialog("close");

					var str = $("#original_text_partial").val();
					str = jQuery.trim(str);

					var str2 = $("#standard_text_partial").val();
					str2 = jQuery.trim(str2);

					$.ajax({
						type : "POST",
						url : "symptomsMaintain.do",
						dataType : 'text',
						data : {
							str : str,
							str2 : str2,
							button : "5"
						},

						error : function(xhr) {

						},
						success : function(Data) {
							if (Data = "success") {

								alert("新增成功");
								location.reload();
							}

						}
					});

				},
				"取消" : function() {
					$(this).dialog("close");

				}
			}
		});
	});

}
// ------------------------------------------------------------------------
function ModifiedDatabaseFunction(e) {
	$(function() {
		$("#dialog-modified_confirm").dialog({
			resizable : true,
			height : 500,
			modal : true,
			buttons : {
				"確定" : function() {
					$(this).dialog("close");

					var str = $("#original_text_partial").val();
					str = jQuery.trim(str);

					var str2 = $("#standard_text_partial").val();
					str2 = jQuery.trim(str2);

					$.ajax({
						type : "POST",
						url : "symptomsMaintain.do",
						dataType : 'text',
						data : {
							str : str,
							str2 : str2,
							button : "9"
						},

						error : function(xhr) {

						},
						success : function(Data) {
							if (Data = "success") {

								alert("修改成功");
								$("#original_text_partial").val('');
								$("#standard_text_partial").val('');
							}

						}
					});

				},
				"取消" : function() {
					$(this).dialog("close");

				}
			}
		});
	});

}
// ------------------------------------------------------------------------
function DeleteDatabaseFunction(e) {
	$(function() {
		$("#dialog-delete_confirm").dialog({
			resizable : true,
			height : 500,
			modal : true,
			buttons : {
				"確定" : function() {
					$(this).dialog("close");

					var str = $("#original_text_partial").val();
					str = jQuery.trim(str);

					$.ajax({
						type : "POST",
						url : "symptomsMaintain.do",
						dataType : 'text',
						data : {
							str : str,
							button : "10"
						},

						error : function(xhr) {

						},
						success : function(Data) {
							if (Data = "success") {

								alert("刪除成功");

								$("#original_text_partial").val('');
								$("#standard_text_partial").val('');

							}

						}
					});

				},
				"取消" : function() {
					$(this).dialog("close");

				}
			}
		});
	});

}
// ------------------------------------------------------------------------
function SymptomsClass(e) {

	// alert($(this).val());

	$.ajax({
		type : "POST",
		url : "symptomsMaintainData.jsp",
		dataType : 'html',

		data : {
			type : $(this).val()

		},

		error : function(xhr) {
			alert("Ajax request error!");

		},
		success : function(DataList) {

			$("#SymptomsClasstest").html(DataList);

		}
	});
}
// -----------------------------------------------------------------------
function countChecked(e) {
	var method = $("input[name='checkbx']:checked").val(); // radio 取值，注意寫法
	var split = method.split('#');

	$("#original_text_partial").val(split[0]);
	$("#standard_text_partial").val(split[1]);

}
// ------------------------------------------------------------------------
function Add_Symptoms(text) {
	var a = $("#standard_text_partial").val();
	a = jQuery.trim(a);
	a = a + text + "。";
	$("#standard_text_partial").val(a);

}
// ------------------------------------------------------------------------
function showStandard(e) {

	var str = $("#original_text_partial").val();
	str = jQuery.trim(str);

	$("#original_text_partial").val(str);

	$.ajax({
		type : "POST",
		url : "symptomsSearch.do",
		dataType : 'json',

		data : {
			original_text : $("#original_text_partial").val(),
			button : "1"
		},

		error : function(xhr) {
			alert("Ajax request error!");

		},
		success : function(DataList) {
			var text_new = "";
			var text_new_not_in_db = "";
			var pattern = "";
			//var in_database = false;
			$.each(DataList, function(index, Data) {

				$.each(Data.modified_Data_list, function(index, modified_Data) {

					if (modified_Data.modified != "不存在資料庫") {
						pattern = pattern + modified_Data.modified + "。";
						//in_database = true;
					}
					else{
						
						pattern = pattern + "不存在資料庫" + "。";
						
					}
				});

				

					text_new = text_new + Data.org + "\n";
					//pattern = pattern.substring(0, pattern.length - 1);
					pattern = pattern + "\n";

			

				

			

				//in_database = false;

			});
			$("#original_text_partial").val(text_new);
			$("#standard_text_partial").val(pattern);

		}
	});
}
// -----------------------------------------------------------------------
function ExortTable(e) {

	

	$.ajax({
		type : "POST",
		url : "symptomsMaintain.do",
		dataType : 'text',

		data : {
			
			button : "6"
		},

		error : function(xhr) {
			alert("Ajax request error!");

		},
		success : function(DataList) {
			if (Data = "success") {

				alert("匯出成功");

			}

		}
	});
}
// -----------------------------------------------------------------------
$(document).ready(function(e) {
	document.getElementById("dialog-modified_confirm").style.display = "none";// 隱藏
	document.getElementById("dialog-delete_confirm").style.display = "none";// 隱藏
	document.getElementById("dialog-add_confirm").style.display = "none";// 隱藏
	$("input[type=button]").button().click(function(event) {
		event.preventDefault();
	});
	$("#clickBtn").click(showStandard);

	$("input[type=radio]").click(countChecked);
	// $("input[type=radio]").on("click", countChecked);

	$("#SymptomsClass").on("change", SymptomsClass);
	$("#SymptomsClasstest").html("<option >請選擇</option>");

	$("#submit_1").click(function(event) {
		var str = $("#SymptomsClasstest").val();
		Add_Symptoms(str);

	});
	$("#ExortTable").click(ExortTable);
	$("#UpdateToDatabase").click(SaveToDatabaseFunction);
	$("#ModifiedDatabase").click(ModifiedDatabaseFunction);
	$("#DeleteDatabase").click(DeleteDatabaseFunction);
	$("#reset").click(function(event) {
		$("#original_text_partial").val('');
		$("#standard_text_partial").val('');

	});

});